{extends 'admin/layout/table-main.tpl'}

{block title}订单管理{/block}
{block smallTitle}系统内的订单管理。{/block}

{block main}
<div class="ibox float-e-margins">
	<div class="ibox-content">
		<div class="row row-lg">
			<div class="col-sm-12">
				<!-- Example Events -->
				<div class="example-wrap">
					<h4 class="example-title">{block title}{/block}</h4>
					<div class="example">
						<div class="btn-group hidden-xs" id="exampleTableEventsToolbar" role="group">
							<form method="get" action="">
								<span>订单号：</span><input type="text" name="id" value="{$get.id}"/>&nbsp;&nbsp;
								{*<span>状态：</span>*}
								{*<select class="small m-wrap" tabindex="1" name="status">*}
									{*<option value="">请选择</option>*}
									{*{foreach $status as $key=>$item}*}
										{*<option value="{$key}" {if $get.status eq $key}selected="selected" {/if}>{$item}</option>*}
									{*{/foreach}*}
								{*</select>*}
								{*&nbsp;&nbsp;*}
								{*<span>阶段：</span>*}
								{*<select class="small m-wrap" tabindex="1" name="step">*}
									{*<option value="">请选择</option>*}
									{*{foreach $step as $key=>$item}*}
										{*<option value="{$key}" {if $get.step eq $key}selected="selected" {/if}>{$item}</option>*}
									{*{/foreach}*}
								{*</select>*}
								&nbsp;&nbsp;
								<span>用户昵称/真实姓名/电话号码：</span><input type="text" name="user" value="{$get.user}"/>
								<span>快递单号：</span><input type="text" name="courier_number" value="{$get.courier_number}"/></br></br>
								<span>订单创建时间：</span>
								<input type="text" id="start_at" name="start_at" value="{$get.start_at}" class="m-wrap date-range" onclick="WdatePicker({ dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{ $dp.$D(\'end_at\')}'})" value="2015-10-28">
								-
								<input type="text" id="end_at" name="end_at" value="{$get.end_at}" onclick="WdatePicker({ dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{ $dp.$D(\'start_at\')}'})" value="2015-10-28" class="m-wrap date-range">
								&nbsp;&nbsp;
								<button class="btn btn-white " type="submit">
									<i class="fa fa-search"></i>
									搜索
								</button>
								<a type="button" class="btn btn-outline btn-default" href="{route('AdminOrderEdit')}">
									<i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
								</a>
								<a type="button" class="btn btn-outline btn-default" href="{route('AdminOrderExcel',$get)}">
									 导出
								</a>
								<a type="button" class="btn btn-outline btn-default dl_courier_number">
									导入快递单号
								</a>
							</form>
							<a type="button" class="btn btn-outline btn-default" onclick="post(1)">
								一键发货
							</a>
						</div>
						<table id="exampleTablePagination" data-toggle="table" data-mobile-responsive="true">
							<thead>
							<tr>
								{*<th data-field="state" data-checkbox="false"></th>*}
								{*<th data-field="id">订单号</th>*}
								<th><input type=checkbox onclick=sel(this)>&nbsp;&nbsp;#</th>
								<th data-field="info" style="width: 80px;">订单信息</th>
								<th data-field="bj" style="width: 80px;">备注</th>
								<th data-field="status">状态</th>
								<th data-field="step">阶段</th>
								<th data-field="member">用户</th>
								<th data-field="mobile">用户手机号</th>
								<th data-field="area">地区</th>
								{*<th data-field="pay_mode">付款方式</th>*}
								<th data-field="channel">渠道</th>
								<th data-field="time">创建时间</th>
								<th>快递单号</th>
								<th data-field="price">操作</th>
							</tr>
							</thead>
							<tbody>
							{foreach $data as $key=>$item}
								<tr data-id="{$item.id}" data-name="{$item.username|escape}" data-type="order" >
									{*<td>{$item.id}</td>*}
									<td><input name="m" type=checkbox value="{$item.id}">&nbsp;&nbsp;<span {if $item.repeat_tag eq 1}style="color: red"{/if}>{$item.id}</span></td>
									<td>
										{$item.OrderGoodsInfo}
										产品型号:
										{foreach $item.goods as $row}
											{$row.goods_number}&nbsp;
										{/foreach}
									</td>
									<td>
										{$item.Follows}
									</td>
									<td>
										<select class="small m-wrap change-status" tabindex="1" name="status">
											{foreach $status as $k=>$row}
												<option value="{$k}" {if $item.status eq $k}selected="selected" {/if}>{$row}</option>
											{/foreach}
										</select>
									</td>
									<td>
										<select class="small m-wrap change-step" tabindex="1" >
											{foreach $step as $k=>$row}
												<option value="{$k}" {if $item.step eq $k}selected="selected" {/if}>{$row}</option>
											{/foreach}
										</select>
										{*{$step[$item.step]}*}
									</td>
									<td>{$item.real_name}</td>
									<td>{$item.member.mobile}</td>
									<td>{$item.location}</td>
									{*<td>{$pay_mode[$item.pay_mode]}</td>*}
									<td>{$item.channel.name}</td>
									<td>{$item.created_at}</td>
									<td><input id="courier_number_{$key}" data-key="{$key}" data-id="{$item.id}" class="courier_number" value="{$item.courier_number}"></td>
									<td>
										<a class="btn btn-xs btn-info" href="{route('AdminOrderEdit', ['id'=>$item.id])}"><i class="fa fa-edit"></i> 编辑</a>
										<button class="btn btn-xs btn-primary openedit" type="button" data-url="{route('AdminOrderCustomerServiceReturn',['id'=>$item.id])}" ><i class="fa fa-tag"></i> 回访</button>
										<button class="btn btn-xs btn-primary openLogisticsTrajectory" type="button" data-url="{route('AdminOrderLogisticsTrajectory',['id'=>$item.id])}" ><i class="fa fa-tag"></i> 物流轨迹</button>
										<button class="btn btn-xs btn-danger" type="button" data-role="delete"><i class="fa fa-trash-o"></i> 删除</button>
									</td>
								</tr>
							{/foreach}
							</tbody>
						</table><br>
						<div style="float: right"><a type="button" class="btn btn-outline btn-default dl_courier_number">
								导入快递单号
							</a></div>
						{include 'admin/layout/paginate.tpl'}
					</div>
				</div>
				<!-- End Example Events -->
			</div>
		</div>
	</div>
</div>
{/block}

{block script}
	<script src="{asset('admin/js/plugins/layer/layer.min.js')}"></script>
	<script>
		$(document).ready(function(){
			$('[data-role="delete"]').on('click', function(){
				var data = $(this).parents('tr').data();
				iconfirm({
					action	: '{route('AdminGlobalIndividalDeletion')}',
					body		: '确定要删除订单吗？',
					data		: data
				});
				return false;
			});

			$('.openedit').click(function(){
				var url = $(this).attr('data-url');
				layer.open({
					type: 2,
					title: false,
					shadeClose: false,
					shade: 0.8,
					area: ['800px', '400px'],
					content: url
				});
			});

			$('.openLogisticsTrajectory').click(function(){
				var url = $(this).attr('data-url');
				layer.open({
					type: 2,
					title: false,
					shadeClose: false,
					shade: 0.8,
					area: ['800px', '400px'],
					content: url
				});
			});

			$('.courier_number').change(function(){
				var id = $(this).data('id');
				var val = $(this).val();
				var key = $(this).data('key');
				var end_2= val.substr(val.length-2);
				var str = val.substr(0,val.length-2);
				var r = 1;
				for (var i=parseInt(key)+1;i<15;i++){
					$('#courier_number_'+i).val(str+(parseInt(end_2)+r));
					r++;
				}
//				console.log(val);
			});

			$('.dl_courier_number').click(function(){
				var data = new Array();
				$('.courier_number').each(function(index){
//					data[index] = new Array();
//					data[index]['courier_number'] = $(this).val();
//					data[index]['id'] = $(this).data('id');
					data[index] = $(this).val()+ '|' + $(this).data('id');
				});
				var v = { };
				v.data = data;
				iconfirm({
					action	: '{route('AdminOrderImportCourierNumber')}',
					body		: '确定要导入快递单号吗？',
					data		: v
				});
				return false;
			});

			$('.change-step').change(function(){
				var data = $(this).children('option:selected').val();
				var id = $(this).parents('tr').data('id');
				var v = { };
				v.data = data;
				v.id = id;
				iconfirm({
					action	: '{route('AdminOrderChangeStep')}',
					body		: '确定要修改订单阶段吗？',
					data		: v
				});
			});

			$('.change-status').change(function(){
				var data = $(this).children('option:selected').val();
				var id = $(this).parents('tr').data('id');
				var v = { };
				v.data = data;
				v.id = id;
				iconfirm({
					action	: '{route('AdminOrderChangeStatus')}',
					body		: '确定要修改订单状态吗？',
					data		: v
				});
			});
		})
	</script>
	<script language=javascript>
		function sel(o)
		{
			var a = document.getElementsByName("m");
			for (var i=0;i<a.length;i++){
				a[i].checked = o.checked;
			}
		}

		function post(e){
			var compatibility = "",
					input = document.getElementsByName("m"),
					value;
			for (var i = 0; i < input.length; i++) {
				if (input[i].type == "checkbox") {
					if (input[i].checked) {
						value = input[i].value;
						compatibility += value + ",";
					}
				}
			}
			var v = { };
			v.type = e;
			v.ids = compatibility;
			iconfirm({
				action	: '{route('AdminOrderAKeyDelivery')}',
				body		: '确定要发货吗？',
				data		: v
			});
		}
	</script>
{/block}
